<?php

include_once($_SERVER['DOCUMENT_ROOT'].'/bs/include/header_ad.inc');
include_once($_SERVER['DOCUMENT_ROOT'].'/bs/include/comp.inc');
include_once($_SERVER['DOCUMENT_ROOT'].'/bs/include/fcs.php');
?>


<?php

if(isset($_GET['task']))
{
		if(!$link=mysql_connect("localhost",$user,$pass))
			die("Error in Database Connection");

		if(!mysql_select_db("bs"))
			echo("Error in Database Selection");

		if($_GET['task']=="displayform")
		{
			if((int)date("m")<4)
			{
				$fromdate="01-04-".((int)date("Y")-1);
				$todate="31-03-".((int)date("Y"));
			}
			else
			{
				$fromdate="01-04-".date("Y");
				$todate="31-03-".((int)date("Y")+1);
			}
			
?>

				| <a href="balance_sheet.php?task=displayform">Balance Sheet</a></div>
				<h3>Select Interval</h3>
				<table cellpadding="3" class="list">
				<form name="displayform" action="<?php echo $_SERVER['PHP_SELF']?>" method="get">
				<tr><td><label>From </label></td><td> <input type="text" name="fromdate" size="12" value="<?php echo $fromdate; ?>" /></td></tr>
				<tr><td><label>To </label></td><td> <input type="text" name="todate" size="12" value="<?php echo $todate; ?>" /></td></tr>
				
				<tr><td align="center"><input type="submit" value="Display" align="absmiddle" /></td></tr>
				<input type="hidden" name="task" value="display" />
				</form>
				</table>
			
		
<?php
		}//END OF TASK=DISPLAY FORM
		if($_GET['task']=="display")
		{
				$valid=1;
				echo "	| <a href='balance_sheet.php?task=displayform'>Balance Sheet</a></div> ";
				
				//VALIDATING DATEs
				
				if(!ereg("^[0-3]?[0-9][\./\-][0-1]?[0-9][\-]20[0-9][0-9]$",$_GET['fromdate'])) 
				{
						echo "Check Your Input 'From' Date<br>";
						$valid=0;
				}
				else
				{
					$datearr=explode("-",$_GET['fromdate']);
					if(!checkdate($datearr[1],$datearr[0],$datearr[2]))
					{
							echo "Check Your Input 'From' Date<br>";
							$valid=0;
					}
					else
							$fromdate=date("Y-m-d",mktime(0,0,0,$datearr[1],$datearr[0],$datearr[2]));
				}
				
				
				if(!ereg("^[0-3]?[0-9][\./\-][0-1]?[0-9][\-]20[0-9][0-9]$",$_GET['todate'])) 
				{
						echo "Check Your Input 'To' Date<br>";
						$valid=0;
				}
				else
				{
					$datearr=explode("-",$_GET['todate']);
					if(!checkdate($datearr[1],$datearr[0],$datearr[2]))
					{
							echo "Check Your Input 'To' Date<br>";
							$valid=0;
					}
					else
							$todate=date("Y-m-d",mktime(0,0,0,$datearr[1],$datearr[0],$datearr[2]));
				}
				
				
				echo"<h3>Balance Sheet From <font color='#FF6600'>{$_GET['fromdate']}</font> To <font color='#FF6600'>{$_GET['todate']}</font></h3>";	
				///
				global $pandl_current,$pandl_period,$diffopb;

				$sum_lib=0;$sum_ast=0;
				
				
	
				///


				
				echo"<div class='head'>";
				echo"<div class='left'>";
				echo"<h5>Liabilities</h5>";
				$sum_lib=display_lib_groups();
				
				
				
				//DISPLAY PROFIT AND LOSS
				$pandl_current=0;$pandl_period=0;				
				calculate_p_and_l();				
				if($pandl_current>0)
				{
					$sum_lib+=$pandl_current;
					echo "<div class='left_err'> Profit & Loss </div><div class='right_err'>{$pandl_current}</div>";
				}
				if($pandl_period>0)
				{
					$sum_lib+=$pandl_period;
					echo "<div class='left_err'> Opening Profit & Loss </div><div class='right_err'>{$pandl_period}</div>";
				}

				
				//DISPLAY DIFFERENCE IN OPENING BALANCE				
				$diffopb=0;
				calculate_diffopb();				
				if($diffopb>0)
				{
					$sum_lib+=$diffopb;
					echo "<div class='left_err'> Diff in Opening Balance</div><div class='right_err'>{$diffopb}</div>";
				}
				echo"</div>";
				



				echo"<div class='right'>";
				echo"<h6>Assets</h6>";
				$sum_ast=display_ast_groups();
				//DISPLAY PROFIT AND LOSS
				$pandl_current=0;$pandl_period=0;				
				calculate_p_and_l();				
				if($pandl_current<0)
				{
					
					$pandl_current=abs($pandl_current);
					$sum_ast+=$pandl_current;
					echo "<div class='left_err'> Profit & Loss </div><div class='right_err'>{$pandl_current}</div>";
				}
				if($pandl_period<0)
				{
					$pandl_period=abs($pandl_period);
					$sum_ast+=$pandl_period;
					echo "<div class='left_err'> Opening Profit & Loss </div><div class='right_err'>{$pandl_period}</div>";
				}

				
				//DISPLAY DIFFERENCE IN OPENING BALANCE				
				$diffopb=0;
				calculate_diffopb();				
				if($diffopb<0)
				{
					$diffopb=abs($diffopb);
					$sum_ast+=$diffopb;
					echo "<div class='left_err'> Diff in Opening Balance</div><div class='right_err'>{$diffopb}</div>";
				}


				echo"</div>";
				echo"</div>";
				
				
				echo "<div class='head_first'> ";			
				
				echo "<div class='head_first_left'> ";			
				echo "<hr>";
				echo "<div class='first'><h1>Total</h1></div><div class='second'><h1>{$sum_lib}</h1></div>";
				
			
				echo "</div>";
				
				echo "<div class='head_first_right'> ";			
				echo "<hr>";
				echo "<div class='third'> <h1>Total</h1></div><div class='second'><h1>{$sum_ast}</h1></div>";
				echo "</div>";
				
				echo "</div>";


				
				
				
				
				
					
				
				

		
		
		}//END OF TASK=DISPLAY
}//END OF ISSET GET


?>
